@microsoft/omnichannel-chat-widget 0.1.0-main.c2417f9 → 0.1.0-main.ce08f21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/lib/cjs/common/Constants.js +4 -0
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +7 -0
  3. package/lib/cjs/common/utils.js +58 -5
  4. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
  5. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  6. package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -3
  7. package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
  8. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  9. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
  11. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  12. package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
  13. package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
  14. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  15. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -2
  16. package/lib/cjs/components/livechatwidget/common/endChat.js +52 -20
  17. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -0
  18. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  19. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  20. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  21. package/lib/cjs/components/livechatwidget/common/startChat.js +152 -81
  22. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +167 -112
  23. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
  24. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  25. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  26. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  27. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
  28. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  29. package/lib/cjs/contexts/createReducer.js +8 -0
  30. package/lib/cjs/controller/componentController.js +3 -3
  31. package/lib/esm/common/Constants.js +4 -0
  32. package/lib/esm/common/telemetry/TelemetryConstants.js +7 -0
  33. package/lib/esm/common/utils.js +45 -3
  34. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
  35. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  36. package/lib/esm/components/headerstateful/HeaderStateful.js +4 -3
  37. package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
  38. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  39. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  40. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
  41. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  42. package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
  43. package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
  44. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  45. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -2
  46. package/lib/esm/components/livechatwidget/common/endChat.js +53 -21
  47. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +9 -2
  48. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  49. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  50. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  51. package/lib/esm/components/livechatwidget/common/startChat.js +147 -80
  52. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +164 -112
  53. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
  54. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  55. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  56. package/lib/esm/contexts/common/ConversationState.js +3 -2
  57. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
  58. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  59. package/lib/esm/contexts/createReducer.js +8 -0
  60. package/lib/esm/controller/componentController.js +3 -3
  61. package/lib/types/common/Constants.d.ts +2 -0
  62. package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
  63. package/lib/types/common/utils.d.ts +6 -3
  64. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
  65. package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
  66. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  67. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  68. package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
  69. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  70. package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
  71. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +4 -3
  72. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  73. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  74. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  75. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
  76. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  77. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  78. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  79. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
  80. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
  81. package/package.json +4 -3
@@ -167,6 +167,10 @@ _defineProperty(Constants, "internetConnectionTestUrlText", "Omnichannel Connect
167
167
 
168
168
  _defineProperty(Constants, "ChatWidgetStateChangedPrefix", "ChatWidgetStateChanged");
169
169
 
170
+ _defineProperty(Constants, "PostChatLoadingDurationInMs", 2000);
171
+
172
+ _defineProperty(Constants, "BrowserUnloadConfirmationMessage", "Do you want to leave chat?");
173
+
170
174
  const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
171
175
  exports.Regex = Regex;
172
176
 
@@ -58,6 +58,8 @@ exports.BroadcastEvent = BroadcastEvent;
58
58
  BroadcastEvent["MaximizeChat"] = "MaximizeChat";
59
59
  BroadcastEvent["ChatInitiated"] = "ChatInitiated";
60
60
  BroadcastEvent["CloseChat"] = "CloseChat";
61
+ BroadcastEvent["InitiateEndChatOnBrowserUnload"] = "InitiateEndChatOnBrowserUnload";
62
+ BroadcastEvent["ClosePopoutWindow"] = "ClosePopoutWindow";
61
63
  })(BroadcastEvent || (exports.BroadcastEvent = BroadcastEvent = {}));
62
64
 
63
65
  let TelemetryEvent;
@@ -139,6 +141,10 @@ exports.TelemetryEvent = TelemetryEvent;
139
141
  TelemetryEvent["AudioToggleButtonClicked"] = "AudioToggleButtonClicked";
140
142
  TelemetryEvent["SuppressBotMagicCodeSucceeded"] = "SuppressBotMagicCodeSucceeded";
141
143
  TelemetryEvent["SuppressBotMagicCodeFailed"] = "SuppressBotMagicCodeFailed";
144
+ TelemetryEvent["GetConversationDetailsException"] = "GetConversationDetailsException";
145
+ TelemetryEvent["BrowserUnloadEventStarted"] = "BrowserUnloadEventStarted";
146
+ TelemetryEvent["GetAuthTokenCalled"] = "GetAuthTokenCalled";
147
+ TelemetryEvent["ReceivedNullOrEmptyToken"] = "ReceivedNullOrEmptyToken";
142
148
  TelemetryEvent["ProcessingHTMLTextMiddlewareFailed"] = "ProcessingHTMLTextMiddlewareFailed";
143
149
  TelemetryEvent["ProcessingSanitizationMiddlewareFailed"] = "ProcessingSanitizationMiddlewareFailed";
144
150
  TelemetryEvent["FormatTagsMiddlewareJSONStringifyFailed"] = "FormatTagsMiddlewareJSONStringifyFailed";
@@ -210,6 +216,7 @@ class TelemetryConstants {
210
216
  case TelemetryEvent.MessageSent:
211
217
  case TelemetryEvent.MessageReceived:
212
218
  case TelemetryEvent.CustomContextReceived:
219
+ case TelemetryEvent.BrowserUnloadEventStarted:
213
220
  return ScenarioType.ACTIONS;
214
221
 
215
222
  case TelemetryEvent.StartChatSDKCall:
@@ -3,14 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setTabIndices = exports.setFocusOnSendBox = exports.setFocusOnElement = exports.preventFocusToMoveOutOfElement = exports.parseAdaptiveCardPayload = exports.newGuid = exports.isNullOrUndefined = exports.isNullOrEmptyString = exports.getWidgetEndChatEventName = exports.getWidgetCacheId = exports.getTimestampHourMinute = exports.getLocaleDirection = exports.getIconText = exports.getDomain = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.createTimer = exports.changeLanguageCodeFormatForWebChat = void 0;
6
+ exports.setTabIndices = exports.setFocusOnSendBox = exports.setFocusOnElement = exports.preventFocusToMoveOutOfElement = exports.parseAdaptiveCardPayload = exports.newGuid = exports.isUndefinedOrEmpty = exports.isNullOrUndefined = exports.isNullOrEmptyString = exports.getWidgetEndChatEventName = exports.getWidgetCacheId = exports.getTimestampHourMinute = exports.getStateFromCache = exports.getLocaleDirection = exports.getIconText = exports.getDomain = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.createTimer = exports.changeLanguageCodeFormatForWebChat = exports.addDelayInMs = void 0;
7
7
 
8
8
  var _Constants = require("./Constants");
9
9
 
10
+ var _DataStoreManager = require("./contextDataStore/DataStoreManager");
11
+
10
12
  var _KeyCodes = require("./KeyCodes");
11
13
 
12
14
  var _TelemetryConstants = require("./telemetry/TelemetryConstants");
13
15
 
16
+ var _md5Typescript = require("md5-typescript");
17
+
14
18
  const getElementBySelector = selector => {
15
19
  let element;
16
20
 
@@ -352,14 +356,63 @@ const getDomain = hostValue => {
352
356
 
353
357
  exports.getDomain = getDomain;
354
358
 
355
- const getWidgetCacheId = (orgId, widgetId) => {
356
- return `${_Constants.Constants.ChatWidgetStateChangedPrefix}_${orgId}_${widgetId}`;
359
+ const getWidgetCacheId = (orgId, widgetId, widgetInstanceId) => {
360
+ const widgetCacheId = `${widgetInstanceId}_${orgId}_${widgetId}`;
361
+ return _md5Typescript.Md5.init(widgetCacheId);
357
362
  };
358
363
 
359
364
  exports.getWidgetCacheId = getWidgetCacheId;
360
365
 
361
- const getWidgetEndChatEventName = (orgId, widgetId) => {
366
+ const getWidgetEndChatEventName = (orgId, widgetId, widgetInstanceId) => {
367
+ if (!isNullOrEmptyString(widgetInstanceId)) {
368
+ return `${_TelemetryConstants.BroadcastEvent.ChatEnded}_${widgetInstanceId}_${orgId}_${widgetId}`;
369
+ }
370
+
362
371
  return `${_TelemetryConstants.BroadcastEvent.ChatEnded}_${orgId}_${widgetId}`;
372
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
373
+
374
+
375
+ exports.getWidgetEndChatEventName = getWidgetEndChatEventName;
376
+
377
+ const getStateFromCache = (orgId, widgetId, widgetInstanceId) => {
378
+ // Getting updated state from cache
379
+ try {
380
+ if (_DataStoreManager.DataStoreManager.clientDataStore) {
381
+ var _DataStoreManager$cli;
382
+
383
+ const widgetStateEventName = getWidgetCacheId(orgId, widgetId, widgetInstanceId);
384
+ const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
385
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
386
+ return persistedState;
387
+ } else {
388
+ return null;
389
+ }
390
+ } catch (error) {
391
+ console.log(error);
392
+ return null;
393
+ }
394
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
395
+
396
+
397
+ exports.getStateFromCache = getStateFromCache;
398
+
399
+ const isUndefinedOrEmpty = object => {
400
+ if (object) {
401
+ if (Object.keys(object).length === 0) {
402
+ return true;
403
+ }
404
+
405
+ return false;
406
+ } else {
407
+ return true;
408
+ }
409
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
410
+
411
+
412
+ exports.isUndefinedOrEmpty = isUndefinedOrEmpty;
413
+
414
+ const addDelayInMs = ms => {
415
+ return new Promise(resolve => setTimeout(resolve, ms));
363
416
  };
364
417
 
365
- exports.getWidgetEndChatEventName = getWidgetEndChatEventName;
418
+ exports.addDelayInMs = addDelayInMs;
@@ -82,6 +82,10 @@ const ChatButtonStateful = props => {
82
82
  titleText: "We're Offline",
83
83
  subtitleText: "No agents available",
84
84
  onClick: async () => {
85
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
86
+ Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonClicked
87
+ });
88
+
85
89
  if (state.appStates.isMinimized) {
86
90
  dispatch({
87
91
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
@@ -41,7 +41,6 @@ const ConfirmationPaneStateful = props => {
41
41
  const {
42
42
  prepareEndChat
43
43
  } = props; // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
44
 
46
45
  const [adapter] = (0, _useChatAdapterStore.default)();
47
46
  const controlProps = {
@@ -72,7 +72,8 @@ const HeaderStateful = props => {
72
72
  } else {
73
73
  const skipEndChatSDK = true;
74
74
  const skipCloseChat = false;
75
- await endChat(adapter, skipEndChatSDK, skipCloseChat);
75
+ const postMessageToOtherTabs = true;
76
+ await endChat(adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTabs);
76
77
  }
77
78
 
78
79
  dispatch({
@@ -81,8 +82,8 @@ const HeaderStateful = props => {
81
82
  });
82
83
  },
83
84
  ...(headerProps === null || headerProps === void 0 ? void 0 : headerProps.controlProps),
84
- hideTitle: state.appStates.conversationState === _ConversationState.ConversationState.Loading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
85
- hideIcon: state.appStates.conversationState === _ConversationState.ConversationState.Loading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
85
+ hideTitle: state.appStates.conversationState === _ConversationState.ConversationState.Loading || state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
86
+ hideIcon: state.appStates.conversationState === _ConversationState.ConversationState.Loading || state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
86
87
  hideCloseButton: state.appStates.conversationState === _ConversationState.ConversationState.Loading || state.appStates.conversationState === _ConversationState.ConversationState.Prechat || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP3 = headerProps.controlProps) === null || _headerProps$controlP3 === void 0 ? void 0 : _headerProps$controlP3.hideCloseButton)
87
88
  };
88
89
  const outOfOfficeControlProps = {
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ActivityStreamHandler = void 0;
7
+
8
+ var _Deferred = require("./Deferred");
9
+
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+
12
+ class ActivityStreamHandler {
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+
16
+ /**
17
+ * Use of a deferred pattern, to hold the execution of the activity.
18
+ *
19
+ * */
20
+ static cork() {
21
+ ActivityStreamHandler.restoreDeferred = new _Deferred.Deferred();
22
+ ActivityStreamHandler.restorePromise = ActivityStreamHandler.restoreDeferred.promise;
23
+ }
24
+ /**
25
+ * Resolve the promise, releasing it to continue with the execution of the activity.
26
+ *
27
+ * */
28
+
29
+
30
+ static uncork() {
31
+ ActivityStreamHandler.restoreDeferred.resolve();
32
+ }
33
+
34
+ }
35
+
36
+ exports.ActivityStreamHandler = ActivityStreamHandler;
37
+
38
+ _defineProperty(ActivityStreamHandler, "restoreDeferred", {
39
+ resolve: () => {
40
+ return "initialState";
41
+ }
42
+ });
43
+
44
+ _defineProperty(ActivityStreamHandler, "restorePromise", void 0);
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DefaultActivitySubscriber = void 0;
7
+
8
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+
10
+ class DefaultActivitySubscriber {
11
+ constructor() {
12
+ _defineProperty(this, "observer", void 0);
13
+ }
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ async next(activity) {
17
+ this.observer.next(activity);
18
+ return false;
19
+ }
20
+
21
+ }
22
+
23
+ exports.DefaultActivitySubscriber = DefaultActivitySubscriber;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PauseActivitySubscriber = void 0;
7
+
8
+ var _ActivityStreamHandler = require("../ActivityStreamHandler");
9
+
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+
12
+ class PauseActivitySubscriber {
13
+ constructor() {
14
+ _defineProperty(this, "observer", void 0);
15
+ }
16
+
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ async apply(activity) {
19
+ await _ActivityStreamHandler.ActivityStreamHandler.restorePromise;
20
+ return activity;
21
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
22
+
23
+
24
+ applicable(activity) {
25
+ return true;
26
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+
28
+
29
+ async next(activity) {
30
+ if (this.applicable(activity)) {
31
+ return await this.apply(activity);
32
+ }
33
+
34
+ return activity;
35
+ }
36
+
37
+ }
38
+
39
+ exports.PauseActivitySubscriber = PauseActivitySubscriber;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ChatAdapterShim = void 0;
7
+
8
+ var _DefaultActivitySubscriber = require("./ActivitySubscriber/DefaultActivitySubscriber");
9
+
10
+ var _shareObservable = require("./shareObservable");
11
+
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+
14
+ class ChatAdapterShim {
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ constructor(chatAdapter) {
20
+ _defineProperty(this, "chatAdapter", void 0);
21
+
22
+ _defineProperty(this, "activityObserver", void 0);
23
+
24
+ _defineProperty(this, "subscribers", void 0);
25
+
26
+ this.subscribers = [];
27
+ this.chatAdapter = { ...chatAdapter,
28
+ activity$: (0, _shareObservable.shareObservable)( // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ new window.Observable(observer => {
30
+ this.activityObserver = observer; // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+
32
+ const abortController = new window.AbortController();
33
+
34
+ (async () => {
35
+ try {
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ for await (let activity of chatAdapter.activities({
38
+ signal: abortController.signal
39
+ })) {
40
+ for (const subscriber of [...this.subscribers, new _DefaultActivitySubscriber.DefaultActivitySubscriber()]) {
41
+ subscriber.observer = this.activityObserver;
42
+ activity = await subscriber.next(activity);
43
+
44
+ if (!activity) {
45
+ break;
46
+ }
47
+ }
48
+ }
49
+
50
+ observer.complete();
51
+ } catch (error) {
52
+ observer.error(error);
53
+ }
54
+ })();
55
+
56
+ return () => {
57
+ abortController.abort();
58
+ };
59
+ }))
60
+ };
61
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+
63
+
64
+ addSubscriber(subscriber) {
65
+ this.subscribers.push(subscriber);
66
+ }
67
+
68
+ }
69
+
70
+ exports.ChatAdapterShim = ChatAdapterShim;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Deferred = void 0;
7
+
8
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+
10
+ class Deferred {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ constructor() {
13
+ _defineProperty(this, "_promise", void 0);
14
+
15
+ _defineProperty(this, "_resolve", void 0);
16
+
17
+ _defineProperty(this, "_reject", () => {
18
+ return;
19
+ });
20
+
21
+ _defineProperty(this, "resolve", value => {
22
+ this._resolve(value);
23
+ });
24
+
25
+ _defineProperty(this, "reject", value => {
26
+ this._reject(value);
27
+ });
28
+
29
+ this._promise = new Promise((resolve, reject) => {
30
+ this._resolve = resolve;
31
+ this._reject = reject;
32
+ });
33
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+
35
+
36
+ get promise() {
37
+ return this._promise;
38
+ }
39
+
40
+ }
41
+
42
+ exports.Deferred = Deferred;
@@ -13,6 +13,10 @@ var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcont
13
13
 
14
14
  var _defaultMiddlewareLocalizedTexts = require("../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts");
15
15
 
16
+ var _ChatAdapterShim = require("./ChatAdapterShim");
17
+
18
+ var _PauseActivitySubscriber = require("./ActivitySubscriber/PauseActivitySubscriber");
19
+
16
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
21
  const createAdapter = async chatSDK => {
18
22
  const chatAdapterOptionalParams = {
@@ -34,7 +38,15 @@ const createAdapter = async chatSDK => {
34
38
  }
35
39
  }
36
40
  };
37
- return await chatSDK.createChatAdapter(chatAdapterOptionalParams);
41
+ let adapter = await chatSDK.createChatAdapter(chatAdapterOptionalParams); //so far, there is no need to convert to the shim adapter when using visual tests
42
+
43
+ if (chatSDK.isMockModeOn !== true) {
44
+ adapter = new _ChatAdapterShim.ChatAdapterShim(adapter);
45
+ adapter.addSubscriber(new _PauseActivitySubscriber.PauseActivitySubscriber());
46
+ return adapter.chatAdapter;
47
+ }
48
+
49
+ return adapter;
38
50
  };
39
51
 
40
52
  exports.createAdapter = createAdapter;
@@ -26,26 +26,40 @@ const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineMarkdown
26
26
  breaks: !disableNewLineMarkdownSupport
27
27
  }); // ToDo: Commenting below usage of plugin until deferred bug is resolved: https://github.com/mayashavin/markdown-it-slack/issues/1
28
28
  // markdown.use(MarkdownSlack);
29
- // Markdown override for open link in new tab
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, quotes
29
+ } else {
30
+ markdown = new _markdownIt.default(_Constants.Constants.Zero, {
31
+ html: true,
32
+ linkify: true,
33
+ breaks: !disableNewLineMarkdownSupport
34
+ });
35
+ markdown.enable(["entity", // Rule to process html entity - {, ¯, "
36
+ "linkify", // Rule to replace link-like texts with link nodes
37
+ "html_block", // Rule to process html blocks and paragraphs
38
+ "html_inline", // Rule to process html tags
39
+ "newline" // Rule to proceess '\n'
40
+ ]);
41
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
42
 
32
- markdown.use(_markdownItForInline.default, "url_new_win", "link_open", function (tokens, idx, env) {
33
- const targetAttrIndex = tokens[idx].attrIndex(_Constants.Constants.Target); // Put a transparent pixel instead of the "open in new window" icon, so developers can easily modify the icon in CSS.
34
43
 
35
- const TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
44
+ markdown.use(_markdownItForInline.default, "url_new_win", "link_open", function (tokens, idx, env) {
45
+ const targetAttrIndex = tokens[idx].attrIndex(_Constants.Constants.Target); // Put a transparent pixel instead of the "open in new window" icon, so developers can easily modify the icon in CSS.
36
46
 
37
- if (~targetAttrIndex) {
38
- tokens[idx].attrs[targetAttrIndex][1] = _Constants.Constants.Blank;
39
- } else {
40
- tokens[idx].attrPush([_Constants.Constants.Target, _Constants.Constants.Blank]);
41
- }
47
+ const TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
48
+
49
+ if (~targetAttrIndex) {
50
+ tokens[idx].attrs[targetAttrIndex][1] = _Constants.Constants.Blank;
51
+ } else {
52
+ tokens[idx].attrPush([_Constants.Constants.Target, _Constants.Constants.Blank]);
53
+ }
54
+
55
+ const relAttrIndex = tokens[idx].attrIndex(_Constants.Constants.TargetRelationship);
42
56
 
43
- const relAttrIndex = tokens[idx].attrIndex(_Constants.Constants.TargetRelationship);
57
+ if (~relAttrIndex) {
58
+ tokens[idx].attrs[relAttrIndex][1] = _Constants.Constants.TargetRelationshipAttributes;
59
+ } else {
60
+ tokens[idx].attrPush([_Constants.Constants.TargetRelationship, _Constants.Constants.TargetRelationshipAttributes]);
44
61
 
45
- if (~relAttrIndex) {
46
- tokens[idx].attrs[relAttrIndex][1] = _Constants.Constants.TargetRelationshipAttributes;
47
- } else {
48
- tokens[idx].attrPush([_Constants.Constants.TargetRelationship, _Constants.Constants.TargetRelationshipAttributes]);
62
+ if (!disableMarkdownMessageFormatting) {
49
63
  tokens[idx].attrPush([_Constants.Constants.Title, _defaultMarkdownLocalizedTexts.defaultMarkdownLocalizedTexts.MARKDOWN_EXTERNAL_LINK_ALT]); // eslint-disable-next-line quotes
50
64
 
51
65
  const iconTokens = markdown.parseInline(`![${_defaultMarkdownLocalizedTexts.defaultMarkdownLocalizedTexts.MARKDOWN_EXTERNAL_LINK_ALT}](${TRANSPARENT_GIF})`, env)[0].children;
@@ -55,21 +69,8 @@ const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineMarkdown
55
69
  tokens.splice(idx + 2, 0, ...iconTokens);
56
70
  }
57
71
  }
58
- });
59
- } else {
60
- markdown = new _markdownIt.default(_Constants.Constants.Zero, {
61
- html: true,
62
- linkify: true,
63
- breaks: !disableNewLineMarkdownSupport
64
- });
65
- markdown.enable(["entity", // Rule to process html entity - {, ¯, "
66
- "linkify", // Rule to replace link-like texts with link nodes
67
- "html_block", // Rule to process html blocks and paragraphs
68
- "html_inline", // Rule to process html tags
69
- "newline" // Rule to proceess '\n'
70
- ]);
71
- }
72
-
72
+ }
73
+ });
73
74
  return markdown;
74
75
  };
75
76
 
@@ -1434,7 +1434,6 @@ const dummyDefaultProps = {
1434
1434
  startNewChatButtonClassName: undefined
1435
1435
  }
1436
1436
  },
1437
- authClientFunction: undefined,
1438
1437
  isReconnectEnabled: undefined,
1439
1438
  reconnectId: undefined,
1440
1439
  redirectInSameWindow: undefined
@@ -1705,6 +1704,7 @@ const dummyDefaultProps = {
1705
1704
  fwdUrl: ""
1706
1705
  }
1707
1706
  },
1708
- telemetryConfig: undefined
1707
+ telemetryConfig: undefined,
1708
+ getAuthToken: undefined
1709
1709
  };
1710
1710
  exports.dummyDefaultProps = dummyDefaultProps;
@@ -27,18 +27,35 @@ var _utils = require("../../../common/utils");
27
27
 
28
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
29
  const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
30
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
30
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
31
31
 
32
32
  const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
33
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
34
- const conversationDetails = await chatSDK.getConversationDetails();
33
+ const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode; // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
34
 
36
- if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
35
+ let conversationDetails = undefined;
36
+
37
+ try {
38
+ conversationDetails = await chatSDK.getConversationDetails();
39
+ } catch (erorr) {
40
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
41
+ Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsException,
42
+ ExceptionDetails: {
43
+ exception: `Failed to get conversation details: ${erorr}`
44
+ }
45
+ });
46
+ }
47
+
48
+ if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
37
49
  const skipEndChatSDK = false;
38
50
  const skipCloseChat = true;
39
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, true);
51
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, false);
40
52
 
41
53
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
54
+ dispatch({
55
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
56
+ payload: _ConversationState.ConversationState.PostchatLoading
57
+ });
58
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
42
59
  const loadPostChatEvent = {
43
60
  eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
44
61
  };
@@ -50,9 +67,11 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
50
67
  payload: _ConversationState.ConversationState.InActive
51
68
  });
52
69
  }
53
- } else {
54
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
70
+
71
+ return;
55
72
  }
73
+
74
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
56
75
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
76
 
58
77
 
@@ -65,16 +84,7 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
65
84
  Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCall
66
85
  });
67
86
 
68
- await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat()); // Need to clear these states immediately when chat ended from OC.
69
-
70
- dispatch({
71
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
72
- payload: undefined
73
- });
74
- dispatch({
75
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
76
- payload: undefined
77
- });
87
+ await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
78
88
  } catch (ex) {
79
89
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
80
90
  Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCallFailed,
@@ -85,7 +95,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
85
95
 
86
96
  postMessageToOtherTab = false;
87
97
  }
88
- }
98
+ } // Need to clear these states immediately when chat ended from OC.
99
+
100
+
101
+ dispatch({
102
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
103
+ payload: undefined
104
+ });
105
+ dispatch({
106
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
107
+ payload: undefined
108
+ });
109
+ dispatch({
110
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
111
+ payload: undefined
112
+ });
89
113
 
90
114
  if (!skipCloseChat) {
91
115
  try {
@@ -117,11 +141,19 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
117
141
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
118
142
  payload: 0
119
143
  });
144
+ dispatch({
145
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
146
+ payload: {
147
+ proactiveChatBodyTitle: "",
148
+ proactiveChatEnablePrechat: false,
149
+ proactiveChatInNewWindow: false
150
+ }
151
+ });
120
152
 
121
153
  if (postMessageToOtherTab) {
122
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
154
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps;
123
155
 
124
- const endChatEventName = (0, _utils.getWidgetEndChatEventName)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId);
156
+ const endChatEventName = (0, _utils.getWidgetEndChatEventName)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId) ?? "");
125
157
 
126
158
  _omnichannelChatComponents.BroadcastService.postMessage({
127
159
  eventName: endChatEventName